package org.xhy;

import com.alibaba.dashscope.embeddings.TextEmbeddingResultItem;
import org.xhy.db.LabelDAO;
import org.xhy.llm.ChatRequest;
import org.xhy.llm.ChatResponse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.xhy.embeding.Embedding.basicCall;
import static org.xhy.llm.DashscopeApiRequest.sendRequest;

public final class Main {


    public static void main(String[] args) throws Exception {
        search();
    }
    // 插入数据
    public static void insert() throws Exception {
        LabelDAO labelDAO = new LabelDAO();
        List<String> names = Arrays.asList("java");
        List<TextEmbeddingResultItem> textEmbeddingResultItems = basicCall(names);
        ArrayList<List<Double>> lists = new ArrayList<>();
        for (TextEmbeddingResultItem textEmbeddingResultItem : textEmbeddingResultItems) {
            List<Double> embedding = textEmbeddingResultItem.getEmbedding();
            lists.add(embedding);
            labelDAO.insertLabel(names.get(textEmbeddingResultItem.getTextIndex()),embedding);
        }
    }
    // 查询数据
    public static void search() throws Exception {
        LabelDAO labelDAO = new LabelDAO();
        List<String> names = Arrays.asList("java","c语言","大数据","金毛","拉布拉多","功夫足球","毒液3","美国队长","绿皮书");
        List<TextEmbeddingResultItem> textEmbeddingResultItems = basicCall(names);
        ArrayList<List<Double>> lists = new ArrayList<>();
        for (TextEmbeddingResultItem textEmbeddingResultItem : textEmbeddingResultItems) {
            List<Double> embedding = textEmbeddingResultItem.getEmbedding();
            lists.add(embedding);
        }
        List<String> similarLabelsBatch = labelDAO.findSimilarLabelsBatch(lists);
        String systemPrompt = "我将提供两组标签。你的任务是：1. 提取第一组标签的特征，包括类别、属性和相关概念，并确保第一组的标签本身也被包含。2. 在第二组标签中，找到与这些特征相关的标签，包括相同类别、属性或相关概念，尽可能多地匹配。3. 只输出筛选出的第二组标签。请确保匹配基于特征的相似性和关联性，而不仅限于字面上的相同。确保第一组的标签在输出中被包含。";
        String userInput = "第一组标签：" + names + "第二组标签："+ similarLabelsBatch.toString();
        ChatRequest chatRequest = new ChatRequest("qwen-max-2024-09-19",systemPrompt,userInput);
        ChatResponse chatResponse = sendRequest(chatRequest);
        System.out.println(chatResponse);

    }
}